#ifndef __IIC_BMP280_H
#define __IIC_BMP280_H
#include <stdint.h>

extern float Pressure;      // 压力值
extern float Temperature;   // 温度值

// I2C地址
#define BMP280_I2C_ADDR  0x76

// 寄存器定义
enum
{
  BMP280_REGISTER_DIG_T1              = 0x88,
  BMP280_REGISTER_DIG_T2              = 0x8A,
  BMP280_REGISTER_DIG_T3              = 0x8C,
  BMP280_REGISTER_DIG_P1              = 0x8E,
  BMP280_REGISTER_DIG_P2              = 0x90,
  BMP280_REGISTER_DIG_P3              = 0x92,
  BMP280_REGISTER_DIG_P4              = 0x94,
  BMP280_REGISTER_DIG_P5              = 0x96,
  BMP280_REGISTER_DIG_P6              = 0x98,
  BMP280_REGISTER_DIG_P7              = 0x9A,
  BMP280_REGISTER_DIG_P8              = 0x9C,
  BMP280_REGISTER_DIG_P9              = 0x9E,
  BMP280_REGISTER_CHIPID              = 0xD0,
  BMP280_REGISTER_SOFTRESET           = 0xE0,
  BMP280_REGISTER_CONTROL             = 0xF4,
  BMP280_REGISTER_CONFIG              = 0xF5,
  BMP280_REGISTER_PRESSUREDATA        = 0xF7,
  BMP280_REGISTER_TEMPDATA            = 0xFA,
};

// 校准参数结构体
typedef struct
{
  uint16_t dig_T1;
  int16_t  dig_T2;
  int16_t  dig_T3;
  uint16_t dig_P1;
  int16_t  dig_P2;
  int16_t  dig_P3;
  int16_t  dig_P4;
  int16_t  dig_P5;
  int16_t  dig_P6;
  int16_t  dig_P7;
  int16_t  dig_P8;
  int16_t  dig_P9;
} bmp280_calib_data;

// IIC接口函数声明------如果使用软件IIC，使用修改下面接口函数即可
void IIC_BMP280_Init(void);
int8_t BMP280_I2C_Read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);
int8_t BMP280_I2C_Write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);


// BMP280操作函数
uint8_t BMP280_Init(void);
float BMP280_ReadTemperature(void);
float BMP280_ReadPressure(void);

#endif
